<template>
  <a-card :bordered="false">
    <div style="display: flex; justify-content: space-between">
      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('订单表')">导出</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
        </a-dropdown>
      </div>
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-form-item label="城市服务商" style="margin-right: 10px" v-has="'xhdjRevenueDetailsRecord:select'">
            <serveSelect @selectClick="selectClick" :value="queryParam.agencyCode"></serveSelect>
          </a-form-item>
          <a-form-item label="收入类型" style="margin-right: 10px">
            <a-select
              v-model="queryParam.type"
              :options="types"
              style="width: 120px"
              placeholder="请选择"
              @change="searchQuery"
            >
            </a-select>
          </a-form-item>
          <a-form-item label="入账状态" style="margin-right: 10px">
            <a-select
              v-model="queryParam.ifAccount"
              :options="ifAccounts"
              style="width: 120px"
              placeholder="请选择"
              @change="searchQuery"
            >
            </a-select>
          </a-form-item>
          <a-form-item label="技师编号" style="margin-right: 10px">
            <a-input placeholder="请输入技师编号" v-model="queryParam.coachId" @pressEnter="searchQuery"></a-input>
          </a-form-item>
          <a-form-item label="技师名称" style="margin-right: 10px">
            <a-input placeholder="请输入技师名称" v-model="queryParam.coachName" @pressEnter="searchQuery"></a-input>
          </a-form-item>
          <a-form-item label="来源订单" style="margin-right: 10px">
            <a-input placeholder="请输入来源订单" v-model="queryParam.orderNumber" @pressEnter="searchQuery"></a-input>
          </a-form-item>
          <a-form-item label="开始时间" style="margin-right: 10px">
            <a-date-picker v-model="queryParam.startTime" :valueFormat="'YYYY-MM-DD'" @change="startChange" />
          </a-form-item>
          <a-form-item label="结束时间" style="margin-right: 10px">
            <a-date-picker
              v-model="queryParam.endTime"
              :valueFormat="'YYYY-MM-DD'"
              @change="endChange"
              :disabled-date="disabledDate"
            />
          </a-form-item>
        </a-form>
      </div>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <span style="margin-right: 20px"
          >总收入：<span style="font-size: 16px; color: red">{{ parseFloat(totalMoney || 0).toFixed(2) }} </span
          >元</span
        >
      </div>
    </div>
    <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
    <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      class="j-table-force-nowrap"
      @change="handleTableChange"
    >
      <template slot="amount" slot-scope="text, record">
        <div v-if="record.type == 0 && record.patternType !== 1">
          <div>合计：{{ parseFloat(record.amount || 0).toFixed(2) }}元</div>
          <div>首单：{{ record.firstOrderAmount }}元</div>
          <div>升级/加钟:{{ record.speedOrderAmount }}元</div>
        </div>

        <div v-else>{{ parseFloat(record.amount || 0).toFixed(2) }} 元</div>
        <a-tag :color="ifAccounts[record.ifAccount].color">
          {{ ifAccounts[record.ifAccount].label }}
        </a-tag>
        <a-tag :color="types[record.type].color">
          {{ types[record.type].label }}
        </a-tag>
      </template>

      <template slot="rate" slot-scope="text, record">
        <div>
          <div v-if="record.type == 0 && record.patternType !== 1">
            <div>首单：{{ record.rate }}%</div>
            <div>升级加钟：{{ record.speedOrderRate }}%</div>
          </div>

          <div v-else>{{ record.rate ? record.rate : '' }}%</div>
        </div>
      </template>

      <template slot="addUpToPayTotal" slot-scope="text, record">
        <div>
          合计服务费：<span class="font-amount">{{ record.totalServiceAmount }}</span
          >元
        </div>
        <div>
          优惠卷：<span class="font-amount">{{ record.preferentialAmount }}</span
          >元
        </div>
        <div>
          车费：<span class="font-amount">{{ record.carAmount }}</span
          >元
        </div>
        <div>
          退款金额：<span class="font-amount">{{ record.orderRefundAmount }}</span
          >元
        </div>
        <div>
          合计付款金额：<span class="font-amount">{{ record.addUpToPayTotal }}</span
          >元
        </div>
      </template>
    </a-table>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <!-- <xhdjOrderInfo-modal ref="modalForm" @ok="modalFormOk"></xhdjOrderInfo-modal> -->
    <!-- <XhdjOrderInfoDialog ref="dialogForm"></XhdjOrderInfoDialog> -->
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
// import XhdjOrderInfoModal from './modules/XhdjOrderInfoModal'
import { getAction, httpAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import serveSelect from '@/components/serveSelect.vue'

// import XhdjOrderInfoDialog from './modules/XhdjOrderInfoDialog.vue'
export default {
  name: 'xhdjRevenueDetailsRecordList',
  mixins: [JeecgListMixin],
  components: {
    serveSelect
  },
  data () {
    return {
      description: '订单表管理页面',
      typeW: 2,
      options: [
        { label: '车费', value: '0' },
        { label: '服务', value: '1' }
      ],
      ifAccounts: [
        { label: '未入账', value: '0', color: 'red' },
        { label: '已入账', value: '1', color: 'green' }
      ],
      sourceTypes: {
        0: '项目返佣',
        1: '充值返佣'
      },
      types: [
        { label: '服务收入', value: '0', color: 'purple' },
        { label: '车费收入', value: '1', color: 'pink' },
        { label: '佣金收入', value: '2', color: 'orange' },
        { label: '服务补款', value: '3', color: 'red' }
      ],
      orderNum: 0,
      totalMoney: 0,
      // 表头
      columns: [
        {
          title: '技师编码',
          align: 'center',
          dataIndex: 'coachId'
        },
        {
          title: '订单编号',
          align: 'center',
          dataIndex: 'orderNumber'
        },
        {
          title: '支付信息',
          align: 'center',
          dataIndex: 'addUpToPayTotal',
          scopedSlots: { customRender: 'addUpToPayTotal' }
        },
        {
          title: '技师昵称',
          align: 'center',
          dataIndex: 'coachName'
        },
        {
          title: '收支金额',
          align: 'center',
          dataIndex: 'amount',
          scopedSlots: { customRender: 'amount' }
        },
        {
          title: '提成比例',
          align: 'center',
          dataIndex: 'rate',
          scopedSlots: { customRender: 'rate' }
          // customRender: (text, record) => {
          //   if (record.type == 0 && record.patternType !== 1) {
          //     return '首单比例:' + record.rate + '%,升级加钟比例' + record.speedOrderRate + '%'
          //   } else {
          //     return record.rate ? record.rate + '%' : ''
          //   }
          // }
        },
        {
          title: '提成模式',
          align: 'center',
          dataIndex: 'patternType',
          customRender: (text, record) => {
            // return record.type !== 0 ? '无' : record.patternType === 1 ? '提成方案A' : '提成方案B'
            if (record.type !== 0) {
              return '无';
            } else if (record.patternType === 1) {
              return '提成方案A';
            } else if (record.patternType === 2) {
              return '提成方案B';
            } else if (record.patternType === 3) {
              return '提成方案C';
            }
          }
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createTime'
        }
      ],

      url: {
        list: '/coach/xhdjCoachIncomeExpenses/list',
        listes: '/coach/xhdjCoachIncomeExpenses/statistics'
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  created () {
    this.init()
  },
  methods: {
    selectClick (value) {
      this.queryParam.agencyCode = value
      this.searchQuery()
    },
    init () {
      var params = this.getQueryParams() //查询条件
      getAction(this.url.listes, params).then(res => {
        if (res.code === 200) {
          console.log(res)
          let { totalAmount } = res.result
          this.totalMoney = totalAmount
        }
      })
    },
    startChange (value) {
      if (value) {
        this.queryParam.startTime = value + ' 00:00:00'
      } else {
        this.queryParam.startTime = value
      }
    },
    endChange (value) {
      if (value) {
        this.queryParam.endTime = value + ' 23:59:59'
      } else {
        this.queryParam.endTime = value
      }
    },
    disabledDate (time) {
      return new Date(time).getTime() < new Date(this.queryParam.startTime).getTime()
    },
    handleReject (id) {
      getAction(this.url.reject, { id }).then(res => {
        if (res.code == 200) {
          that.$message.success(res.message)
          this.loadData()
        } else {
          that.$message.console.error(res.message)
        }
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.ant-row {
  display: flex;
  justify-content: flex-end;
}
.ant-col {
  display: flex;
  justify-content: flex-end;
}
.ant-form {
  display: flex;
}
.j-table-force-nowrap /deep/ .ant-upload-picture-card-wrapper {
  display: block !important;
}
.font-amount {
  color: red;
}
</style>
